package com.central.apps.handler.MaterialInventory;

import com.central.app.service.HandlerService;
import com.central.apps.handler.base.LvBaseHandler;
import com.central.app.common.util.BLuntil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

/**
 * 物资台账
 */
@Component
public class itemHandler  extends LvBaseHandler {
    @Autowired
    private HandlerService handlerService;

    @Override
    public Object operate(String app, String type, Map<String, Object> params) throws Exception {
        HashMap<String,Object> result=new HashMap<String, Object>() ;
        result.put("code",1);
        result.put("resp_msg","操作失败");
        //获取库房
        if("getLocation".equals(type)){
            String itemnum = BLuntil.getParameter(params,"ITEMNUM");
            return BLuntil.toPage(params,handlerService," select warehousenum,warehousedesc from bl_warehouse where warehousenum not in ( "  +
                    " select warehousenum from bl_Inventorys where itemnum='"+itemnum+"')" );
        }
        // 添加到库存
        if("insertInventroy".equals(type)){
            String itemnum = BLuntil.getParameter(params,"ITEMNUM");
            String locations = BLuntil.getParameter(params,"locations");

            String [] location=locations.split(",");

            for(String l : location){
                handlerService.findBySql(" insert into bl_Inventorys (itemnum,itemdesc,warehousenum,warehousedesc,model,caizhi,supply,innum,currentqty,actqty)  " +
                        " select itemnum,description,'"+l+"',(select warehousedesc from bl_warehouse where warehousenum='"+l+"' ),GGXH,'',SCCJ,0,0,0 from bl_wztzitem " +
                        " where itemnum='"+itemnum+"'");

            }
            result.put("code",200);
            result.put("resp_msg","操作成功");


        }
        return result;
    }
}
